#pragma once
#ifndef __BOARD__H__
#define __BOARD__H__

#include "Block.h"
#include "BlockSet.h"

namespace ATSudokuEngine
{

class Board : public Block
{
public:
	Board():nCol_(0), nRow_(0)
	{
	}

	Bool CreateCell(UInt32 nCol, UInt32 nRow);
	Bool DestroyCell();

	Bool Blocks(UInt32 nIndex, BlockSet& aBlockSet) const;

	Bool Row(UInt32 nIndex, Block& aBlock) const;
	Bool Col(UInt32 nIndex, Block& aBlock) const;
	Bool Square(UInt32 nIndex, Block& aBlock) const;

	virtual Bool Set(UInt32 nIndex, UInt32 nValue);

	virtual UInt32 Length() const;

	Bool UpdateAllCandidate() const;

	static void _SquareSize(UInt32 nCol, UInt32 nRow, UInt32& nSquareCol, UInt32& nSquareRow);
	static int _GCD(int u, int v);
	static void _LastestCD(UInt32 nValue, UInt32& nSquareCol, UInt32& nSquareRow);
	static bool _IsDivisibleBy(UInt32 nValue, UInt32 nDivisor);
	static void _SquarePosition(UInt32 nIndex, UInt32 nCol, UInt32 nRow, UInt32 nSquareCol, UInt32 nSquareRow, UInt32& nColOnSquare, UInt32& nRowOnSquare);
protected:
	UInt32 nCol_;
	UInt32 nRow_;
};

}	// namespace ATSudokuEngine

#endif